//
//  ContentView.m
//  SohoNaru
//
//  Created by ladaka31 ladaka on 13. 5. 31..
//  Copyright (c) 2013년 ladaka Inc. All rights reserved.
//

#import "ContentView.h"
#import "ImageScrollView.h"

@implementation ContentView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor whiteColor];
        
        // Initial Layout
        [self initLayout];
        
    }
    return self;
}

-(void) initLayout{
    [self initMainFrame];
    [self initEditViewFrame];
    [self initSubFrame];
    [self initFooterFrame];
}


////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// MAIN Frame ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-(void) initMainFrame{
     mainFrame = [[UIView alloc] initWithFrame:CGRectMake(11, 10, 282, 180)];
    mainFrame.backgroundColor = [UIColor whiteColor];
    [self addSubview:mainFrame];
    
    backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_print_phto_border.png"]];
    [backgroundView setFrame:CGRectMake(0,0, 282, 180)];
    [mainFrame addSubview:backgroundView];
    
    contentScroll = [[ImageScrollView alloc] initWithFrame:CGRectMake(0,0, 282, 180) setImagePath:@"/var/mobile/Applications/B1162015-E622-4CF7-BD4B-23DCA79EB5AF/Documents/1/IMG_0019.PNG"];
    [subContentScroll1_1 setScrollZoom:NO];
    [mainFrame addSubview:contentScroll];
    
    companyName= [[UITextField alloc] initWithFrame:CGRectMake(11, 10, 120, 30)];
    [companyName setText:@"소호나루 카페"];
    [companyName setFont:[UIFont systemFontOfSize:21.0f]];
    [companyName setTextColor:[UIColor whiteColor]];
    [companyName setBackgroundColor:[[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f]];
    [mainFrame addSubview:companyName];
    
    deleteButtonImage = [UIImage imageNamed:@"btn_photo_del.png"];
    deleteHilightButtonImage = [UIImage imageNamed:@"btn_photo_del_ov.png"];
    
    deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setFrame:CGRectMake(0,0, 51, 60)];
    [deleteButton setBackgroundImage:deleteButtonImage forState:UIControlStateNormal];
    [deleteButton setBackgroundImage:deleteHilightButtonImage forState:UIControlStateHighlighted];
    [deleteButton addTarget:self action:@selector(ImageDelete:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setTag:0];
    [mainFrame addSubview:deleteButton];
    
    editButtonImage = [UIImage imageNamed:@"btn_photo_edit.png"];
    editHilightButtonImage = [UIImage imageNamed:@"btn_photo_edit_ov.png"];
    editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [editButton setFrame:CGRectMake(233,0, 51, 60)];
    [editButton setBackgroundImage:editButtonImage forState:UIControlStateNormal];
    [editButton setBackgroundImage:editHilightButtonImage forState:UIControlStateHighlighted];
    [editButton addTarget:self action:@selector(ImageEdit:) forControlEvents:UIControlEventTouchUpInside];
    [editButton setTag:0];
    [mainFrame addSubview:editButton];
}


-(IBAction)ImageDelete:(id)sender{
    NSLog(@"ImageDelete %d",[sender tag]);
    switch ([sender tag]) {
        case 0:
            [contentScroll setImageChange:[UIImage alloc]];
            break;
        default:
            break;
    }
    
}


-(IBAction)ImageEdit:(id)sender{
    NSLog(@"setEditMode %d",[sender tag]);
    switch ([sender tag]) {
        case 0:
            [contentScroll setScrollZoom:YES];
            break;
            
        default:
            break;
    }
    
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// Edit Frame ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-(void) initEditViewFrame{
    editFrame = [[UIView alloc] initWithFrame:CGRectMake(11, 196, 282, 85)];
    editFrame.backgroundColor = [UIColor whiteColor];
    [self addSubview:editFrame];
    
    editBackgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_print_txtbg.png"]];
    [editBackgroundImageView setFrame:CGRectMake(0,0, 282, 85)];
    [editFrame addSubview:editBackgroundImageView];
    
    editView = [[UITextView alloc] initWithFrame:CGRectMake(0,0, 282, 85)];
    [editView setBackgroundColor:[UIColor clearColor]];
    [editFrame addSubview:editView];
    
}


////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// Sub1 and Sub2 Frame ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-(void) initSubFrame{
  
    
    subFrame1 = [[UIView alloc] initWithFrame:CGRectMake(11, 290 , 138, 96)];
    subFrame1.backgroundColor = [UIColor whiteColor];
    [self addSubview:subFrame1];
    
    subView1_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , 68, 50)];
    subView1_1.backgroundColor = [UIColor redColor];
    [subFrame1 addSubview:subView1_1];
    
    subContentScroll1_1 = [[ImageScrollView alloc] initWithFrame:CGRectMake(0,0, 68, 50) setImagePath:@"/var/mobile/Applications/B1162015-E622-4CF7-BD4B-23DCA79EB5AF/Documents/1/IMG_0019.PNG"];
    [subContentScroll1_1 setScrollZoom:NO];
    [subView1_1 addSubview:subContentScroll1_1];
    
    subView1_2 = [[UIView alloc] initWithFrame:CGRectMake(71, 0 , 68, 50)];
    subView1_2.backgroundColor = [UIColor blackColor];
    [subFrame1 addSubview:subView1_2];
    
    subContentScroll1_2 = [[ImageScrollView alloc] initWithFrame:CGRectMake(0,0, 68, 50) setImagePath:@"/var/mobile/Applications/B1162015-E622-4CF7-BD4B-23DCA79EB5AF/Documents/1/IMG_0019.PNG"];
    [subContentScroll1_2 setScrollZoom:NO];
    [subView1_2 addSubview:subContentScroll1_2];
    
    subView1_3 = [[UIView alloc] initWithFrame:CGRectMake(0, 54 , 138, 42)];
    [subFrame1 addSubview:subView1_3];
    
    couponBgImageView1_1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_coupon_bg1.png"]];
    [couponBgImageView1_1 setFrame:CGRectMake(0,0, 53, 42)];
    [subView1_3 addSubview:couponBgImageView1_1];
    
    couponBgImageView2_1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_coupon_bg2.png"]];
    [couponBgImageView2_1 setFrame:CGRectMake(52,0, 86, 42)];
    
    [subView1_3 addSubview:couponBgImageView2_1];
    
    couponLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 42, 21)];
    [couponLabel1 setText:@"coupon"];
    [couponLabel1 setFont:[UIFont systemFontOfSize:9.0f]];
    [couponLabel1 setBackgroundColor:[UIColor clearColor]];
    [couponLabel1 setTextColor:[UIColor whiteColor]];
    [subView1_3 addSubview:couponLabel1];
    
    couponPerLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(4, 16, 46, 21)];
    [couponPerLabel1 setText:@"50%"];
    [couponPerLabel1 setFont:[UIFont systemFontOfSize:21.0f]];
    [couponPerLabel1 setBackgroundColor:[UIColor clearColor]];
    [couponPerLabel1 setTextColor:[[UIColor alloc] initWithRed:255.0f/255.0f green:180.0f/255.0f blue:0.0f alpha:1.0f]];
    [subView1_3 addSubview:couponPerLabel1];
    
    couponNameLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(55, 5, 75, 21)];
    [couponNameLabel1 setText:@"롯데리아 콜라"];
    [couponNameLabel1 setFont:[UIFont systemFontOfSize:13.0f]];
    [couponNameLabel1 setBackgroundColor:[UIColor clearColor]];
    [couponNameLabel1 setTextColor:[UIColor whiteColor]];
    [subView1_3 addSubview:couponNameLabel1];
    
    couponExpireLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(55, 20, 82, 21)];
    [couponExpireLabel1 setText:@"2013.05.30~06.30"];
    [couponExpireLabel1 setFont:[UIFont systemFontOfSize:10.0f]];
    [couponExpireLabel1 setBackgroundColor:[UIColor clearColor]];
    [couponExpireLabel1 setTextColor:[[UIColor alloc] initWithRed:159.0f/255.0f green:159.0f/255.0f blue:159.0f/255.0f alpha:1.0f]];
    [subView1_3 addSubview:couponExpireLabel1];
    
    
    
    subFrame2 = [[UIView alloc] initWithFrame:CGRectMake(155, 290 , 138, 96)];
    subFrame2.backgroundColor = [UIColor whiteColor];
    [self addSubview:subFrame2];
    
    subView2_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0 , 68, 50)];
    subView2_1.backgroundColor = [UIColor redColor];
    [subFrame2 addSubview:subView2_1];
    
    subContentScroll2_1 = [[ImageScrollView alloc] initWithFrame:CGRectMake(0,0, 68, 50) setImagePath:@"/var/mobile/Applications/B1162015-E622-4CF7-BD4B-23DCA79EB5AF/Documents/1/IMG_0019.PNG"];
     [subContentScroll2_1 setScrollZoom:NO];
    [subView2_1 addSubview:subContentScroll2_1];
    
    subView2_2 = [[UIView alloc] initWithFrame:CGRectMake(71, 0 , 68, 50)];
    subView2_2.backgroundColor = [UIColor blackColor];
    [subFrame2 addSubview:subView2_2];
    
    subContentScroll2_2 = [[ImageScrollView alloc] initWithFrame:CGRectMake(0,0, 68, 50) setImagePath:@"/var/mobile/Applications/B1162015-E622-4CF7-BD4B-23DCA79EB5AF/Documents/1/IMG_0019.PNG"];
      [subContentScroll2_2 setScrollZoom:NO];
    [subView2_2 addSubview:subContentScroll2_2];
    
    
    subView2_3 = [[UIView alloc] initWithFrame:CGRectMake(0, 54 , 138, 42)];
    subView2_3.backgroundColor = [UIColor grayColor];
    [subFrame2 addSubview:subView2_3];
    
    couponBgImageView2_1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_coupon_bg1.png"]];
    [couponBgImageView2_1 setFrame:CGRectMake(0,0, 53, 42)];
    [subView2_3 addSubview:couponBgImageView2_1];
    
    couponBgImageView2_2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_coupon_bg2.png"]];
    [couponBgImageView2_2 setFrame:CGRectMake(52,0, 86, 42)];
    [subView2_3 addSubview:couponBgImageView2_2];
    
    couponLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 42, 21)];
    [couponLabel2 setText:@"coupon"];
    [couponLabel2 setFont:[UIFont systemFontOfSize:9.0f]];
    [couponLabel2 setBackgroundColor:[UIColor clearColor]];
    [couponLabel2 setTextColor:[UIColor whiteColor]];
    [subView2_3 addSubview:couponLabel2];
    
    couponPerLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(4, 16, 46, 21)];
    [couponPerLabel2 setText:@"50%"];
    [couponPerLabel2 setFont:[UIFont systemFontOfSize:21.0f]];
    [couponPerLabel2 setBackgroundColor:[UIColor clearColor]];
    [couponPerLabel2 setTextColor:[[UIColor alloc] initWithRed:255.0f/255.0f green:180.0f/255.0f blue:0.0f alpha:1.0f]];
    [subView2_3 addSubview:couponPerLabel2];
    
    couponNameLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(55, 5, 75, 21)];
    [couponNameLabel2 setText:@"롯데리아 콜라"];
    [couponNameLabel2 setFont:[UIFont systemFontOfSize:13.0f]];
    [couponNameLabel2 setBackgroundColor:[UIColor clearColor]];
    [couponNameLabel2 setTextColor:[UIColor whiteColor]];
    [subView2_3 addSubview:couponNameLabel2];
    
    couponExpireLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(55, 20, 82, 21)];
    [couponExpireLabel2 setText:@"2013.05.30~06.30"];
    [couponExpireLabel2 setFont:[UIFont systemFontOfSize:10.0f]];
    [couponExpireLabel2 setBackgroundColor:[UIColor clearColor]];
    [couponExpireLabel2 setTextColor:[[UIColor alloc] initWithRed:159.0f/255.0f green:159.0f/255.0f blue:159.0f/255.0f alpha:1.0f]];
    [subView2_3 addSubview:couponExpireLabel2];

    
}


////////////////////////////////////////////////////////////////////////////////
////////////////////////////// footer Frame ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-(void) initFooterFrame{
   
    footerFrame = [[UIView alloc] initWithFrame:CGRectMake(11, 390, 282, 29)];
    footerFrame.backgroundColor = [UIColor whiteColor];
    [self addSubview:footerFrame];
    
    footerBgImageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_footer_bg1.png"]];
    [footerBgImageView1 setFrame:CGRectMake(0,0, 86, 29)];
    [footerFrame addSubview:footerBgImageView1];
    
    footerBgImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ad_footer_bg2.png"]];
    [footerBgImageView2 setFrame:CGRectMake(86,0, 196, 29)];
    [footerFrame addSubview:footerBgImageView2];
    
    footerCompanyName = [[UILabel alloc] initWithFrame:CGRectMake(3, 4, 80, 21)];
    [footerCompanyName setText:@"소호나라슈퍼"];
    [footerCompanyName setFont:[UIFont systemFontOfSize:15.0f]];
    [footerCompanyName setBackgroundColor:[UIColor clearColor]];
    [footerCompanyName setTextColor:[UIColor whiteColor]];
    [footerFrame addSubview:footerCompanyName];
    
    footerAddress = [[UILabel alloc] initWithFrame:CGRectMake(91, 4, 185, 21)];
    [footerAddress setText:@"서울시 강남구 역삼동 31번지 건암빌딩 902호"];
    [footerAddress setFont:[UIFont systemFontOfSize:10.0f]];
    [footerAddress setBackgroundColor:[UIColor clearColor]];
    [footerAddress setTextColor:[UIColor whiteColor]];
    [footerFrame addSubview:footerAddress];
}

@end
